<?php
namespace Admin\Controller;
use Think\Controller;
class AreasController extends Controller{
    public function AreasAdd(){
    	$areas = M ( 'areas' );
         $area['area_name'] = I('area_name');
         $are = I('area_name');
         $area['createtime'] = time();
         $area['guid'] = 0;
         $area['line'] = 0;
         $area['isDel'] = 0;
         $area['pid'] = I('pid');
         $area['logo_url'] = 0;
         $area['level'] = 0;
         $area['id_line'] = 0;
         $area['is_hot'] =0;
         $area['isMit'] = 0;
         $area['city_domain'] = 0;
         
         $area['other_params'] = 0;
    	// var_dump($area);
        // $info['title'] = I('title');     
        // $info['status'] = I('status');
        // $info['sort'] = I('sort');
        // $info['pid'] = I('pid');
    if ($are!= null) {
 			$re = $areas->add($area);
              if ($re) {
                $this->success("添加成功");
             }else{
                 $this->error("失败");
              }   
    	 }else{
		 	$info = $areas->select();
			      $data = array();
			    foreach($info as $k => $v){
			        if($v['pid'] == 0){
			            $data[]=$v;
			            foreach($info as $k1 => $v1){
			                if($v['id'] == $v1['pid']){
			                    $v1['area_name'] = '---'.$v1['area_name'];
			                    $data[] = $v1;
			                    foreach ($info as $key => $value) {
			                        if($v1['id'] == $value['pid']){
			                            $value['area_name'] = '------------'.$value['area_name'];
			                            $data[]=$value;
			                        }
			                    }
			                }
			            }
			        }
			    }
  	$this->assign ( "data", $data);
        $this->display();
   		 }
    }


















}